<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="handleClick()">死循环</button>
    
    <!-- 小球1使用left改变 -->
    <div class="box box1"></div>    
    <!-- 小球2使用transform改变 -->
    <div class="box box2"></div>
    

</body>
<style>
    .box{
        width: 100px;
        height: 100px;
        border-radius: 50%;
        margin-top: 100px;
    }
    .box1{
        background-color: blue;
        position: relative;
        left: 0;
        animation: move2 2s infinite;
    }
    .box2{
        background-color: red;
        animation: move 2s infinite;
    }
    @keyframes move{
        0%{
            transform: translateX(0);
        }
        50%{    
            transform: translateX(100px);
        }   
        100%{
            transform: translateX(0);
        }
    }
    @keyframes move2{
        0%{
            left: 0;
        }
        50%{
            left: 100px;
        }
        100%{
            left: 0;
        }
    }
    
</style>

</html>
<script>
    
    function delay(ms){
        var start = Date.now();//获取当前时间
        while(Date.now() - start < ms){
            //空循环,直到时间结束
        }
        return;
    }//死循环指定时间
    function handleClick() {
        console.log('死循环开始');
        delay(5000);
        console.log('死循环结束');
    }
</script>